//Create a promise
const promise = new Promise((resolve, reject) => {
    // Do some async task
    setTimeout(() => {
    console.log("异步任务完成");
    resolve();
    }, 1000);
});

// promise.then(() => {
//     console.log("Promise已消耗");
// });

    const getUser = new Promise((resolve, reject) => {
        setTimeout(() => {
            let error = true;

            if (!error) {
                resolve({ name: "John", age: 30 });
            } else {
                reject("发⽣错误。");
            }
        }, 1000);
    });

    getUser.then((user) => {
        console.log(user);
    }).catch((error) => {
        console.log(error);
    }).finally(() => {
        console.log("Promise已解决或被拒绝。");
    });



console.log("来⾃全局作⽤域的输出");